//
//  WebFectcher.m
//  PsychoMeter
//
//  Created by Awais Munir on 12/15/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "WebFectcher.h"
#import "JSONKit.h"

@implementation WebFectcher
@synthesize delegate;
//-(void)callDataWithDictionary:(NSDictionary*)dict{
-(void)callDataWithURL:(NSString*)url andData:(NSDictionary*)dict{
    [dict retain];
    
    
    NSURL *Url = [NSURL URLWithString:url];
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:Url];
    
    [request setHTTPMethod:@"POST"];
    
    NSString *bodyString = [[NSString alloc] initWithFormat:@"problem=%@&address=%@&province=%@&city=%@&area=%@contact=%@",[dict objectForKey:@"problem"],[dict objectForKey:@"street"],[dict objectForKey:@"province"],[dict objectForKey:@"city"],[dict objectForKey:@"area"],[dict objectForKey:@"phone"]];
    
    NSData *requestBody = [bodyString dataUsingEncoding:NSUTF8StringEncoding];
    
    [request setHTTPBody:requestBody];
    
    NSURLResponse *response = NULL;
    
    NSError *requestError = NULL;
    
    NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&requestError];
    NSDictionary *recDict =[responseData objectFromJSONData];// [parser objectWithString:responseString error:nil];
 //   [jsonWriter release];
  //  [parser release];
//	[responseString release];
    [dict release];
    if([self.delegate respondsToSelector:@selector(webFetcherSuccessWithData:)]){
        [self.delegate webFetcherSuccessWithData:recDict];
    }
}
@end
